package cn.wolfcode.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    public static String singningKey = "wolfcode";
    public static Long expiresIn = 3600L;

    public static String generateToken(Map<String, Object> claims) {
        return Jwts.builder().addClaims(claims)
                .signWith(SignatureAlgorithm.HS256, singningKey)
                .setExpiration(new Date(System.currentTimeMillis() + expiresIn))
                .compact();

    }
    public static Claims parseToken(String jwt) {
        return Jwts.parser().setSigningKey(singningKey)
                .parseClaimsJws(jwt)
                .getBody();
    }
}
